package com.songlanyun.modules.marketing.firstorder.controller.admin;


import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.exception.RRException;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.marketing.firstorder.entity.FirstOrderActivity;
import com.songlanyun.modules.marketing.firstorder.model.dto.FirstOrderActivityDTO;
import com.songlanyun.modules.marketing.firstorder.service.FirstOrderActivityService;
import com.songlanyun.modules.user.controller.AbstractController;
import com.songlanyun.modules.user.exception.UserException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.common.utils.R;


/**
 * 首单活动
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-23 16:29:49
 */
@RestController
@RequestMapping("admin/marketing/firstOrder")
public class FirstOrderActivityAdminController extends AbstractController {
    @Autowired
    private FirstOrderActivityService FirstOrderActivityService;


    /**
     * 信息
     */
    @GetMapping("/info")
//    @RequiresPermissions("oss:FirstOrderActivity:info")
    public R info() {
        Long shopId = getShopId();

        FirstOrderActivity FirstOrderActivity = FirstOrderActivityService.getByShopId(shopId,false);

        return R.ok().put("data", FirstOrderActivity);
    }

    /**
     * 保存、修改
     */
    @SysLog("保存、修改首单活动")
    @PostMapping("/save")
//    @RequiresPermissions("oss:FirstOrderActivity:save")
    public R save(@RequestBody FirstOrderActivityDTO dto) {

        ValidatorUtils.validateEntity(dto);
        dto.setShopId(getShopId(true));
        FirstOrderActivityService.saveOrder(dto);

        return R.ok();
    }


    /**
     * 删除
     */
    @SysLog("删除首单活动")
    @DeleteMapping("/delete/{id}")
//    @RequiresPermissions("oss:FirstOrderActivity:delete")
    public R delete(@PathVariable("id") Long id) {
        FirstOrderActivity FirstOrderActivity = FirstOrderActivityService.getById(id, true);
        verifyShopId(FirstOrderActivity.getShopId());
        FirstOrderActivityService.removeById(id);

        return R.ok();
    }

}
